package com.hspedu.newData.面试题;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-19 
 * @Version: 1.0
 */

public class 面试题0402最小高度树 {

    public TreeNode sortedArrayToBST(int[] nums) {

        TreeNode treeNode = findNode(nums,0,nums.length);
        return treeNode;

    }

    public TreeNode findNode(int[] nums,int startIndex,int endIndex){
        if (startIndex>=endIndex){
            return null;
        }

        int mid = startIndex + (endIndex - startIndex)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = findNode(nums,startIndex,mid);
        node.right = findNode(nums,mid+1,endIndex);
        return node;
    }

}
